﻿Imports System.Text

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


        Dim sText As String = cTools.sFileReader()

        Dim dStart As Decimal = sText.IndexOf("第二卷")
        Dim dEnd As Decimal = sText.IndexOf("第三卷")


        sText = sText.Substring(dStart, dEnd - dStart)

        Dim listNav As List(Of String) = cTools.listNav_SE(sText, "第二卷", vbCrLf, True)

        cEPUB.sBookName = "死人经 第二卷 群龙之首"
        cEPUB.sCreator = "冰临神下"
        cEPUB.sFileNB = "Si_Ren_Jing_02"
        cEPUB.StartEpub()
        Dim dNav As Decimal = 1


        For Each sNav As String In listNav

            Dim uChart As cFile = cEPUB.NewCharter(sNav.Replace("第二卷 群龙之首", "").Trim())
            Dim listChart As New List(Of String)

            If dNav = listNav.Count Then
                listChart.Add(sText.Substring(sText.IndexOf(listNav(dNav - 1)) + listNav(dNav - 1).Length))
            Else
                listChart = cTools.listNav_SE(sText, listNav(dNav - 1), listNav(dNav), False)
            End If

            If listChart.Count = 1 Then

                Dim listLine As List(Of String) = listChart(0).Split(vbCrLf).ToList()

                For Each ss As String In listLine
                    If Not ss.Trim() = String.Empty Then
                        uChart.sbText.Append(cEPUB.htmlAddText(ss.Trim()))
                    End If
                Next
            End If
            uChart.sbText.Append(cEPUB.htmlBodyEnd)
            System.IO.File.WriteAllText(uChart.sPath, uChart.sbText.ToString(), Encoding.GetEncoding("utf-8"))
            dNav = dNav + 1
        Next

        cEPUB.EndEpub()

    End Sub
End Class
